﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="../scripts/boot.js" type="text/javascript"></script>
    <script src="../scripts/kindeditor/kindeditor-min.js" type="text/javascript"></script>
    <script src="../scripts/kindeditor/lang/zh_CN.js" type="text/javascript"></script>
    <link href="../scripts/kindeditor/themes/default/default.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        var editor;
        KindEditor.ready(function (K) {
            editor = K.create('textarea[name="nw_content"]', {
                allowFileManager: true
            });
            var uploadbutton = K.uploadbutton({
                button: K('#uploadButton')[0],
                fieldName: 'imgFile',
                url: '../scripts/kindeditor/upload/upload_json.ashx?dir=image',
                afterUpload: function (data) {
                    if (data.error == 0) {
                        $("#img").attr("href", data.url);
                        $(".ke-button").val("重新上传");
                        mini.get("nw_img").setValue(data.url);
                        $("#spanload").show();
                    } else
                        ShowMessage("系统提示", data.message, 2);
                },
                afterError: function (str) {
                    ShowMessage("系统提示", "上传失败！", 3);
                }
            });
            uploadbutton.fileBox.change(function (e) {
                uploadbutton.submit();
            });
        }); 
    </script>
</head>
<body>
    <div id="editform" class="form">
        <input class="mini-hidden" name="nw_no" id="nw_no" />
        <table style="width: 98%; height: 100%;">
            <tr style="height: 20px">
                <td class="tdtitle" style="width: 80px;">
                    标题：
                </td>
                <td class="tdtext">
                    <input name="nw_title" class="mini-textbox" required="true" style="width:700px;"/>
                </td>
            </tr>
            <tr style="height: 20px">
                <td class="tdtitle">
                    类别：
                </td>
                <td class="tdtext">
                    <input name="nw_type" class="mini-combobox" repeatlayout="table" repeatdirection="vertical"
                        style="width:120px;" data="NewsCentre" required="true" />&nbsp;&nbsp;
                    <input name="nw_hide" class="mini-checkbox" text="隐藏"/>&nbsp;
                    <input name="nw_orderid" class="mini-checkbox" text="置顶"/>&nbsp;
                    <input name="nw_red" class="mini-checkbox" text="描红"/>&nbsp;
                    <input name="nw_new" class="mini-checkbox" text="最新"/>
                </td>
            </tr>
            <tr style="height: 20px">
                <td class="tdtitle">
                    图片：
                </td>
                <td class="tdtext">
                    <input class="mini-hidden" name="nw_img" id="nw_img" />
                    <span id="spanload" style="display:none;">已经上传，<a id="img" class="linelink" target="_blank">查看</a>&nbsp;&nbsp;<a class="mini-button" iconcls="icon-remove" onclick="onDelete">删除</a></span>&nbsp;&nbsp;<input type="button" id="uploadButton" value="上传" />
                </td>
            </tr>
            <tr style="height: 20px">
                <td class="tdtitle">
                    内容：
                </td>
                <td class="tdtext">
                    <textarea name="nw_content" style="width:700px;height:300px;visibility:hidden;"></textarea>
                </td>
            </tr>
        </table>
    </div>
    <div property="footer" style="text-align:center;padding:5px;">
        <a class="mini-button" style="width:60px;" onclick="onOk">保存</a>
        <span style="display:inline-block;width:25px;"></span>
        <a class="mini-button" style="width:60px;" onclick="CloseWindow">关闭</a>
    </div>
    <script type="text/javascript">
        $.ajaxSetup({
            contentType: "application/x-www-form-urlencoded;charset=utf-8",
            complete: function (XMLHttpRequest, textStatus) {
                if (XMLHttpRequest.responseText == "out") {
                    var loginWindow = parent.mini.get("loginWindow");
                    if (!loginWindow.visible)
                        loginWindow.show();
                }
            }
        });
        mini.parse();

        var form = new mini.Form("#editform");

        function SaveData() {
            form.validate();
            if (form.isValid() == false) return;

            var o = form.getData();
            var content = editor.html();
            var messageid = mini.loading("保存中，请稍后......", "系统提示");
            var json = mini.encode(o);
            $.ajax({
                url: "../data/system.aspx?method=SaveNews",
                data: { data: json, content: content },
                cache: false,
                success: function (ret) {
                    mini.hideMessageBox(messageid);
                    if (ret == 1) {
                        CloseWindow("1");
                    }
                    else if (ret == 0) {
                        CloseWindow("0");
                    }
                    else if (ret == 2) {
                        CloseWindow("2");
                    }
                    else
                        ShowMessage("系统提示", "资讯保存失败！", 3);
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    mini.hideMessageBox(messageid);
                    ShowMessage("系统提示", "资讯保存失败！", 3);
                }
            });
        }

        ////////////////////
        //标准方法接口定义
        function SetData(data) {
            if (data.action == "edit") {
                //跨页面传递的数据对象，克隆后才可以安全使用
                data = mini.clone(data);

                $.ajax({
                    url: "../data/system.aspx?method=GetNews&id=" + data.id,
                    cache: false,
                    success: function (text) {
                        var o = mini.decode(text);
                        form.setData(o);
                        if (o.nw_img != null && o.nw_img != '') {
                            $("#img").attr("href", o.nw_img);
                            $(".ke-button").val("重新上传");
                            $("#spanload").show();
                        }
                        editor.html(o.nw_content);
                    }
                });
            }
        }

        function GetData() {
            var o = form.getData();
            return o;
        }

        function CloseWindow(action) {
            if (action == "close" && form.isChanged()) {
                if (confirm("数据被修改了，是否先保存？")) {
                    return false;
                }
            }
            if (window.CloseOwnerWindow) 
                return window.CloseOwnerWindow(action);
            else
                window.close();
        }

        function onOk(e) {
            SaveData();
        }

        function onCancel(e) {
            CloseWindow("cancel");
        }

        function onDelete() {
            $("#img").attr("href", "");
            mini.get("nw_img").setValue("");
            $(".ke-button").val("上传");
            $("#spanload").hide();
        }
    </script>
</body>
</html>